package com.unknowpupil.design.prototype;

import java.util.Date;

/**
 * @Description: <br/>
 * <p>
 *    原型模式 1997 英国的克隆羊，多利。
 * </p>
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2020/4/24 21:25
 * @Classname: Sheep
 * @Version: 1.0
 */
public class Sheep implements Cloneable{
    /**
     * 名字
     */
    private String sname;
    /**
     * 生日
     */
    private Date brithday;

    public Sheep(String sname, Date brithday) {
        this.sname = sname;
        this.brithday = brithday;
    }

    /**
     * native 本地方法。
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
       Object obj = super.clone();

       //添加如下代码实现深拷贝。
        Sheep s = (Sheep) obj;
        s.brithday =(Date) this.brithday.clone();
       return obj;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public Date getBrithday() {
        return brithday;
    }

    public void setBrithday(Date brithday) {
        this.brithday = brithday;
    }
}
